﻿'MeaMod Playme
'Developed by The MeaMod Group
'Copyright 2009 The MeaMod Group
'http://meamod.com
'by James Weston
'--------------------------------
Imports System.IO
Imports System.Runtime.InteropServices

Public Class frmCoverArt

    <StructLayout(LayoutKind.Sequential)> _
Public Structure MARGINS
        Public cxLeftWidth As Integer
        Public cxRightWidth As Integer
        Public cyTopHeight As Integer
        Public cyButtomheight As Integer
    End Structure

    <DllImport("dwmapi.dll", CharSet:=CharSet.Auto)> _
    Public Shared Sub DwmExtendFrameIntoClientArea(ByVal hWnd As System.IntPtr, ByRef pMargins As MARGINS)
    End Sub

    <DllImport("dwmapi.dll", CharSet:=CharSet.Auto)> _
    Public Shared Sub DwmIsCompositionEnabled(ByRef IsIt As Boolean)
    End Sub

    Private Sub frmCoverArt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not frmMain.WindowState = FormWindowState.Minimized Then
            Dim Yform As Integer
            Dim Xform As Integer
            Yform = frmMain.Location.Y.ToString + 205
            Xform = frmMain.Location.X + 5
            Me.Location = New System.Drawing.Point(Xform, Yform)
        Else
            Me.StartPosition = FormStartPosition.CenterScreen
        End If
        imgCover2.Image = MeaMod_Playme.My.Resources.Resources.resNocoverartlarge
        If My.Computer.Info.OSVersion >= "6" Then
            Dim margins As MARGINS = New MARGINS
            margins.cxLeftWidth = -1
            margins.cxRightWidth = -1
            margins.cyTopHeight = -1
            margins.cyButtomheight = -1
            Dim isit As Boolean = False
            DwmIsCompositionEnabled(isit)
            If isit Then
                Me.BackColor = System.Drawing.Color.Black
                ' If DWM is enabled, call the function that gives us glass, passing a reference to our inset Margins
                DwmExtendFrameIntoClientArea(Me.Handle, MARGINS)
            End If
        End If
        'set all the four value -1 to apply glass effect to the whole window
        'set your own value to make specific part of the window glassy.
        If VideoLan.VlcState.Playing = False Then
            imgCover2.Image = MeaMod_Playme.My.Resources.Resources.resNocoverartlarge
        Else
            Try
                For Each picture As TagLib.IPicture In frmMain.InfoTag.Tag.Pictures()
                    If picture.Type = TagLib.PictureType.FrontCover Then
                        Dim stream As New MemoryStream(picture.Data.Data)
                        imgCover2.Image = New Bitmap(stream)
                        Exit For
                    End If
                Next
            Catch NullReferenceException As Exception
            End Try
        End If
    End Sub
End Class